package com.jy.authors.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jy.common.annotation.Log;
import com.jy.common.core.controller.BaseController;
import com.jy.common.core.domain.AjaxResult;
import com.jy.common.enums.BusinessType;
import com.jy.authors.domain.Authors;
import com.jy.authors.service.IAuthorsService;
import com.jy.common.utils.poi.ExcelUtil;
import com.jy.common.core.page.TableDataInfo;

/**
 * 作者Controller
 * 
 * @author ruoyi
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/authors/authors")
public class AuthorsController extends BaseController
{
    @Autowired
    private IAuthorsService authorsService;

    /**
     * 查询作者列表
     */
    @PreAuthorize("@ss.hasPermi('authors:authors:list')")
    @GetMapping("/list")
    public TableDataInfo list(Authors authors)
    {
        startPage();
        List<Authors> list = authorsService.selectAuthorsList(authors);
        return getDataTable(list);
    }

    /**
     * 导出作者列表
     */
    @PreAuthorize("@ss.hasPermi('authors:authors:export')")
    @Log(title = "作者", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Authors authors)
    {
        List<Authors> list = authorsService.selectAuthorsList(authors);
        ExcelUtil<Authors> util = new ExcelUtil<Authors>(Authors.class);
        util.exportExcel(response, list, "作者数据");
    }

    /**
     * 获取作者详细信息
     */
    @PreAuthorize("@ss.hasPermi('authors:authors:query')")
    @GetMapping(value = "/{authorId}")
    public AjaxResult getInfo(@PathVariable("authorId") Long authorId)
    {
        return success(authorsService.selectAuthorsByAuthorId(authorId));
    }

    /**
     * 新增作者
     */
    @PreAuthorize("@ss.hasPermi('authors:authors:add')")
    @Log(title = "作者", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Authors authors)
    {
        return toAjax(authorsService.insertAuthors(authors));
    }

    /**
     * 修改作者
     */
    @PreAuthorize("@ss.hasPermi('authors:authors:edit')")
    @Log(title = "作者", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Authors authors)
    {
        return toAjax(authorsService.updateAuthors(authors));
    }

    /**
     * 删除作者
     */
    @PreAuthorize("@ss.hasPermi('authors:authors:remove')")
    @Log(title = "作者", businessType = BusinessType.DELETE)
	@DeleteMapping("/{authorIds}")
    public AjaxResult remove(@PathVariable Long[] authorIds)
    {
        return toAjax(authorsService.deleteAuthorsByAuthorIds(authorIds));
    }
}
